package com.xuecheng.content.controller;

import com.xuecheng.api.content.TeachplanControllerApi;
import com.xuecheng.api.content.model.dto.TeachplanDTO;
import com.xuecheng.api.content.model.dto.TeachplanMediaDTO;
import com.xuecheng.api.content.model.qo.QueryTeachplanMediaModel;
import com.xuecheng.api.content.model.vo.TeachplanVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.TeachplanConvert;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 课程计划 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class TeachplanController implements TeachplanControllerApi {

    @Autowired
    private TeachplanService  teachplanService;

    @GetMapping("/teachplan/{courseBaseId}/tree-nodes")
    public TeachplanDTO queryTree(@PathVariable Long courseBaseId) {
        Long companyId = SecurityUtil.getCompanyId();
        return teachplanService.queryTree(courseBaseId,companyId);
    }

    @PostMapping("/teachplan")
    public TeachplanDTO createOrModifyTeachPlan(@RequestBody TeachplanVO vo) {
        Long companyId = SecurityUtil.getCompanyId();
        TeachplanDTO teachplanDTO = TeachplanConvert.INSTANCE.vo2Dto(vo);
        return teachplanService.createOrModifyTeachPlan(teachplanDTO,companyId);
    }

    @DeleteMapping("/teachplan/{teachPlanId}")
    public boolean removeTeachPlan(@PathVariable Long teachPlanId) {
        Long companyId = SecurityUtil.getCompanyId();
        return teachplanService.removeTeachPlan(teachPlanId,companyId);
    }

    @PostMapping("/teachplan/media/association")
    public TeachplanMediaDTO associateMedia(@RequestBody QueryTeachplanMediaModel qo){
        Long companyId = SecurityUtil.getCompanyId();
        return teachplanService.associateMedia(qo,companyId);
    }

}
